package crp.services.api.graphql;

import com.qwlabs.lang.C2;
import crp.core.academic.app.AcademicService;
import crp.services.api.graphql.models.AcademicYearPayload;
import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Query;

import javax.annotation.security.PermitAll;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
import javax.validation.constraints.NotNull;
import java.util.List;

@GraphQLApi
@RequestScoped
@Transactional
public class AcademicGraphQLApi {
    private final AcademicService academicService;

    @Inject
    public AcademicGraphQLApi(AcademicService academicService) {
        this.academicService = academicService;
    }

    @Query
    @PermitAll
    @NotNull
    public List<@NotNull AcademicYearPayload> academicYears() {
        return C2.list(academicService.searcher().years(), AcademicYearPayload::of);
    }
}
